#include <stdio.h>
long long A=1992919, B=18181971;
FILE *f;
char s[20];
int ts=1;
int next()
{
	A=(A*13166771+B)%1000000007;
	B=(B*67771+A)%1000000007;
	return A;
}
void createtest() { sprintf(s, "%03d", ts); ts++; f=fopen(s, "w"); }
void gen0()
{
	createtest();
	fprintf(f, "3 5\n1\n234\n56789\n");
	createtest();
	fprintf(f, "1 5\n1\n");
}
void gen1(int n, int q)
{
	createtest();
	int i, j;
	for(fprintf(f, "%d %d\n", n, q), i=0; i<n; fprintf(f, "\n"), i++)
		for(j=0; j<=2*i; fprintf(f, "%d", next()%10), j++);
}
int main()
{
	int i;
	gen0();
	for(i=0; i<10; i++)
		gen1(100-i, 100);
	gen1(1000, 5000000);
	gen1(997, 5000000);
	gen1(993, 5000000);
	gen1(989, 5000000);
	return 0;
}